import { query } from '../services/example'
import { routerRedux } from 'dva/router'

export default{
    namespace: 'room',
    state: {
        pwd: "12345678",
        appid: 1400037025,
        roomnum: 0,
        privMap: 255,
        identifier : 0,
        accounttype: 14418,
        closeLocalMedia: false,
    },
    effects: {
        *fetch({ payload }, { call, put }) {  // eslint-disable-line
          const res = yield call(query, payload)
          yield put({ type: 'save',payload:payload});
          if(res.data && res.data.errorCode === 0){
            // const userSig = res.data.userSig;
            // const privateMapKey = res.data.privMapEncrypt;
            yield put({ 
                        type: 'save',
                        payload: res.data,
                    });
            yield put(routerRedux.push('/video'))
          }
        },
        *redirect(_, { put }){
            yield put(routerRedux.push('/'))
        }
      },
    
    reducers: {
        save(state, { payload }) {
            return { ...state, ...payload };
        },
        
    },
}